home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Snippets / PNL Libraries / MyTEUtils.p < prev    next >
Text File  |  1997-01-06  |  2KB  |  85 lines

  1. unit MyTEUtils;
  2.  
  3. interface
  4.  
  5.     uses
  6.         TextEdit;
  7.  
  8.     function TEEditMenuEnabled (te: TEHandle; static: boolean; maxsize: longint): boolean;
  9.     procedure TESetEditMenuItem (te: TEHandle; static: boolean; maxsize: longint; item: integer);
  10.     function TEDoEditMenu (te: TEHandle; static: boolean; maxsize: longint; item: integer): boolean;
  11.  
  12. implementation
  13.  
  14.     uses
  15.         Types, Scrap, Windows, Menus, Quickdraw,
  16.         MyTypes, MyMenus;
  17.  
  18.     function TEEditMenuEnabled (te: TEHandle; static: boolean; maxsize: longint): boolean;
  19.         var
  20.             i: integer;
  21.     begin
  22.         for i := EMundo to EMselectall do begin
  23.             TESetEditMenuItem(te, static, maxsize, i);
  24.         end;
  25.         TEEditMenuEnabled := GetMenuHandle(M_Edit)^^.enableFlags <> 0;
  26.     end;
  27.  
  28.     procedure TESetEditMenuItem (te: TEHandle; static: boolean; maxsize: longint; item: integer);
  29.         var
  30.             offset: longint;
  31.     begin
  32.         case item of
  33.             EMundo: 
  34.                 SetIDItemEnable(M_Edit, item, false);
  35.             EMcut, EMclear: 
  36.                 SetIDItemEnable(M_Edit, item, not static & (te^^.selStart < te^^.selEnd));  { Can cut,clear if there is a selection }
  37.             EMcopy: 
  38.                 SetIDItemEnable(M_Edit, item, te^^.selStart < te^^.selEnd);  { Can copy iff there is a selection }
  39.             EMpaste: 
  40.                 SetIDItemEnable(M_Edit, item, not static & (GetScrap(nil, 'TEXT', offset) > 0) & (TEGetScrapLength + (te^^.teLength - (te^^.selEnd - te^^.selStart)) < maxsize));
  41.             EMselectall: 
  42.                 SetIDItemEnable(M_Edit, item, te^^.teLength > 0);  { Can select all iff there is something to select }
  43.             otherwise begin
  44.                 { do nothing }
  45.             end;
  46.         end;
  47.     end;
  48.  
  49.     function TEDoEditMenu (te: TEHandle; static: boolean; maxsize: longint; item: integer): boolean;
  50.         var
  51.             loe, oe: OSErr;
  52.     begin
  53. {$unused(static, maxsize)}
  54.         TEDoEditMenu := true;
  55.         case item of
  56.             EMcopy:  begin
  57.                 TECopy(te);
  58.                 loe := ZeroScrap;
  59.                 oe := TEToScrap;
  60.                 TEDoEditMenu := false;
  61.             end;
  62.             EMselectall:  begin
  63.                 SetPort(FrontWindow);
  64.                 TESetSelect(0, maxLongInt, te);
  65.                 TEDoEditMenu := false;
  66.             end;
  67.             EMcut:  begin
  68.                 TECut(te);
  69.                 loe := ZeroScrap;
  70.                 oe := TEToScrap;
  71.             end;
  72.             EMclear:  begin
  73.                 TEDelete(te);
  74.             end;
  75.             EMpaste:  begin
  76.                 oe := TEFromScrap;
  77.                 TEPaste(te);
  78.             end;
  79.             otherwise begin
  80.                 { do nothing }
  81.             end;
  82.         end;
  83.     end;
  84.  
  85. end.